using System;
using CBatchArt;
using UnityEngine;
using CSUtils;
using U3dComm;
using U3dUtils;
using UnityCommon;
using CLog = CSUtils.CLog;
//Before--之前
//After--之后
public class U3dHotUpdate {
    const string _tag = "U3dHotUpdate";
    public static string gameName;

    /// <summary>
    /// 游戏初始化入口--热更新入口
    /// </summary>
    public static void Init(string appConfigStr, Action<bool, string> appOpenUICall) {
        try {
            AppStart_Comm.Init(appConfigStr, delegate {
                try {
                    Batch2D_com_u3d_unity_common.Init();
                    Debug.LogError(_tag + ".....游戏初始化入口");
                    if (UpdateApp.CHeckNewVersion()) {
                        return;
                    }
                    //ArtFileList.Init();
                    ArtStart_Comm.Init(() => {
                        StartGame(appOpenUICall);
                        AppStart_Comm.Init2();
                    });
                } catch (Exception ex) {
                    CLog.Ex(_tag, ex);
                }
            });
        } catch (Exception ex) {
            CLog.Ex(_tag, ex);
        }
    }

    static void StartGame(Action<bool, string> appOpenUICall) {
        //CLanguageUtils.RegisterLoadPath($"Halo-Island/Excel2Config");
        AppConfig.RegisterData("gameName", CL.G("gameName"));

        var identifier = BuildInfo.identifier;
        CLog.i(_tag, $"APP包名....{identifier}");
        var arr = identifier.Split('.');
        var gameName = arr[^1];
        CBaseInfo.currGameName = gameName;

        appOpenUICall.Invoke(false, "");

        Admob_Init_com_xia9000_game_g06();
        //UnityEngine.Purchasing.Product kk;

        Game01.Init();
        Game01.Start();
    }

    static void Admob_Init_com_xia9000_game_g06() {
        #if ADMOB
        AdMobContr.appId_android = new[] { "ca-app-pub-3718311388385619~9945349459" };
        AdMobContr.appId_ios = new[] { "ca-app-pub-3718311388385619~4908645195" };

        AdMobContr.banner_android = new[] { "ca-app-pub-3718311388385619/2855997815" };
        AdMobContr.banner_ios = new[] { "ca-app-pub-3718311388385619/8280913992" };

        AdMobContr.interstitial_android = new[] { "ca-app-pub-3718311388385619/5675502774" };
        AdMobContr.interstitial_ios = new[] { "ca-app-pub-3718311388385619/9629289721" };

        AdMobContr.interstitialReward_android = new[] { "ca-app-pub-3718311388385619/3084427635" };
        AdMobContr.interstitialReward_ios = new[] { "ca-app-pub-3718311388385619/1220681623" };

        AdMobContr.reward_android = new[] { "ca-app-pub-3718311388385619/2526595253" };
        AdMobContr.reward_ios = new[] {
            "ca-app-pub-3718311388385619/6113915657", //
            "ca-app-pub-3718311388385619/6501092107", //
            "ca-app-pub-3718311388385619/6361523128", //
            "ca-app-pub-3718311388385619/5812790414", //
            "ca-app-pub-3718311388385619/8909727049", //
        };
        AdMobContr.open_android = new[] { "ca-app-pub-3718311388385619/1771345969" };
        AdMobContr.open_ios = new[] { "ca-app-pub-3718311388385619/4205937611" };
        AdsSDK.Init(true);

        #endif
        //UmengUtils.Start();
    }

    public static void LoadSubArt(int[] artIndexArr, Action<bool, string> callback) {
        UI_Loading.Instance.WaitOpen("下载子项目资源");
        Debug.Log($"准备下载资源...............{artIndexArr.ToStr()}");
        MainAssetsManager.SubArtUpdate(artIndexArr, 0, delegate(int i, string s) {
            UI_Loading.Instance.WaitOpen($"下载子项目..{s}");
            Debug.LogError($"下载子项目..{s}");
        }, UI_Loading.Instance.LoadProgre, delegate(bool b, string s) {
            UI_Loading.Instance.WaitClose();
            callback.Invoke(b, s);
        });
    }
}
